<?php
/*
 * @Author: your name
 * @Date: 2020-06-29 09:28:29
 * @LastEditTime: 2020-09-30 18:02:56
 * @LastEditors: 天羽落星辰
 * @Description: In User Settings Edit
 * @FilePath: \WWW\frx\application\api\controller\Index.php
 */ 

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 我的财务
 */
class Finance extends Api
{
    // protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 我的收益列表
     * @param string $type  类型
     * @param string $limit  页数列表显示条数
     * @param string $paging 页数
     */ 
    public function index()
    {   
        $type = intval($this->request->request('type'));
        $limit = intval($this->request->request('limit'));
        $paging = intval($this->request->request('paging'));
        $limit = $limit ? $limit : 10;
        $paging = $paging ? 10 * $paging : 0;

        if(!$type){
            $type = '4,5,12';
        }elseif($type == 8){
            $type = '8,11';
        }

        $data['count'] = $this->qianbao_sysetm_log_sum($type);
        $data['finance'] = $this->qianbao_sysetm_log($type,$limit, $paging);

        $this->success('',$data);
    }

    // 我的收益总额
    private function qianbao_sysetm_log_sum($type)
    {
        $data = db('qianbao_sysetm_log')
        ->where('uid',$this->auth->id)
        ->where('type','<>',0)
        ->whereIn('type',$type)
        ->sum('money');
        
        return $data;

    }

    // 全部收益
    private function qianbao_sysetm_log($type,$limit, $paging)
    {   
        $data = db('qianbao_sysetm_log')->field('type, money, createtime,bizhong')
        ->where('uid',$this->auth->id)
        ->whereIn('type',$type)
        ->where('type','<>',0)
        ->limit($paging,$limit)
        ->order('id desc')
        ->select();
        if($data){
            foreach($data as &$v){
                // $v['username'] = substr_replace($v['username'], '****', 3, 4); //2.替换字符串的子串
                $v['createtime'] = datetime($v['createtime']);
                if($v['bizhong'] != 'bls_frozen'){
                    $v['bizhong'] = strtoupper($v['bizhong']);
                }else{
                    $v['bizhong'] = 'BLS';
                }
            }
        }

        return $data;
    }
    
   
   
}
